import axios from 'axios'; 
import {
	Loading } from 'vant';
// axios降级请求,处理跨域一个请求发两次的问题
axios.interceptors.request.use(function (config) { 
	config.headers['Content-Type'] = 'application/x-www-form-urlencoded' 
	if (config.method === 'post') { 
//		config.data = qs.stringify({ ...config.data 
//		})
	}
return config; 
}, function (error) {
	loadinginstace.close();
	return Promise.reject(error);
}) 

export const test = () => { 
	console.log('test'); 
}
/** * url * data 请求参数 * type 请求类型 */
export const doajax = (url, data, type) => { 
	let config; 
	if (type === 'get') { 
		config = { 
			method: type, 
			params: data, 
		} 
	} else { 
		config = { 
			method: type, 
			data, 
		} 
	} 
//	console.log('config',config);
	return axios(url, config); 
} 

export const ajax = (url, data, suc) =>{ 
	doajax (url, data, 'get').then((res) => { 
		let { 
			status, 
			msg 
		} = res.data;
if (status === 0) { 
	suc(res.data.data); 
} else { 
	alert(msg); 
		} 
	}); 
}
export const require = (url, data, suc) =>{ 
	doajax (url, data, 'post').then((res) => { 
		let { 
			status, 
			msg 
		} = res.data;
if (status === 0) { 
	suc(res.data.data); 
} else { 
	alert(msg); 
		} 
	}); 
}

